package cn.opopopo.design_pattern_learn.行为型.command;

public class CommandPatternDemo {
    public static void main(String[] args) {
        // 创建接收者
        Light light = new Light();
        AirConditioner ac = new AirConditioner();

        // 创建命令
        Command lightOn = new LightOnCommand(light);
        Command lightOff = new LightOffCommand(light);
        Command acOn = new AirConditionerOnCommand(ac);
        Command setTemp = new SetTemperatureCommand(ac, 22);

        // 创建调用者（遥控器）
        RemoteControl remote = new RemoteControl();

        // 模拟操作
        remote.pressButton(lightOn);
        remote.pressButton(acOn);
        remote.pressButton(setTemp);

        // 撤销
        remote.pressUndo();
        remote.pressUndo();
        remote.pressUndo();
        remote.pressUndo(); // 无操作可撤销
    }
}